//
//  tabbarView.m
//  tabbarTest
//
//  Created by Kevin Lee on 13-5-6.
//  Copyright (c) 2013年 Kevin. All rights reserved.
//

#import "TabbarView.h"



@implementation TabbarView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setFrame:frame];
        [self layoutView];  //设置布局
    }
    return self;
}

-(void)layoutView
{
    _tabbarView = [[UIView alloc]init];
    _tabbarView.backgroundColor = [UIColor whiteColor];
    //设置tabbar顶部的线条
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width,1)];
    lineView.backgroundColor = [UIColor colorWithRed:168/255.0 green:171/255.0 blue:173/255.0 alpha:1.0];
    [self addSubview:lineView];
    
    
    [_tabbarView setFrame:CGRectMake(0, 1, self.frame.size.width, self.frame.size.height)];
    //设置tabbar能接收用户事件
    [_tabbarView setUserInteractionEnabled:YES];

    [self addSubview:_tabbarView];
    
    //设置tabbar中的按钮
    [self layoutBtn];

}

-(void)layoutBtn
{
 
    NSMutableArray *tabBarItmes = [[NSMutableArray alloc] initWithCapacity:5];
    
    NSString *arrTitles[5] = {@"首页",@"信息",@"通讯录",@"应用",@"我"};
    NSString *arrImageSelected[5] = {@"homeTabbar1",@"messageTabBar1",@"addressTabBar1",@"publicTabBar1",@"personalTarBar1"};
    NSString *arrImagesNormal[5] = {@"homeTabbar2",@"messageTabBar2",@"addressTabBar2",@"publicTabBar2",@"personalTarBar2"};
    
   for (int i = 0; i < 5; i ++)
    {
        SYTabBarItem *itemTempA = [[SYTabBarItem alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame) / 5.0, TITLE_BAR_HEGIHT) title:arrTitles[i] selectedImage:[UIImage imageNamed:arrImageSelected[i]] unselectedImage:[UIImage imageNamed:arrImagesNormal[i]]];
        itemTempA.selectedTitleColor = BASIC_BLUE_COLOR;
        itemTempA.unselectedTitleColor = [UIColor colorWithRed:111.0f/255.0f green:111.0f/255.0f blue:111.0f/255.0f alpha:1.0f];
        itemTempA.tag = i;
        [tabBarItmes addObject:itemTempA];
    }
    
    //initalize the tab barA
    _tabbar = [[SYTabBar alloc] initWithSYTabBarItems:tabBarItmes];
    _tabbar.tag = MAINTABBAR;
    _tabbar.showDividingLine = YES;
    

    _tabbar.frame = _tabbarView.frame;
    [_tabbarView addSubview:_tabbar];
}

-(void)setCurrentTab:(int)index {
    [_tabbar selectItemAtIndex:index];
}

-(void)SetMessageNumber:(NSString *)msgnumbers indextar:(NSUInteger) index
{
    [_tabbar setBadgeValue: msgnumbers atIndex:index];
}

@end
